<style >
  table.formTable {
    font-family: verdana, arial, sans-serif;
    font-size: 0.875rem;
    color: #333333;
    border-width: 0px;
    border-color: #dcdfe6;
    border-collapse: collapse;
    width: 100%;
  }

  table.formTable td {
    border-width: 0px;
    padding: 20px;
    border-style: solid;
    border-color: #dcdfe6;
    background-color: #ffffff;
    padding:2px;
    text-align: center;
  }

  table.formTable td:first-child {
    width: 100px;
    text-align: right;
  }

  table.formTable td:last-child {
  	 color: #E6A23C; 
  }
  
      #tableIconForBizStylePoint + .layui-table-view .layui-table-body tbody > tr > td {
        padding: 0;
    }

    #tableIconForBizStylePoint + .layui-table-view .layui-table-body tbody > tr > td > .layui-table-cell {
        height: 60px;
        line-height: 60px;
    }

    .tdImg {
        width: 35px;
        height:35px;
        max-width: none;
        cursor: pointer;
    }

    .layui-table-view {
        margin: 0;
    }
</style>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar" id="tbToolBar">
                <div class="layui-form-item">
					<div class="layui-inline">
						<button id="btnAddBizVideo" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
					</div>
                    <div class="layui-inline" style="float: right;margin-right: 0px;">
						<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;">
							<label class="layui-form-label w-auto">名称</label>
							<div class="layui-input-inline mr0">
								<input name="name" class="layui-input" type="text" placeholder="请输入名称"/>
							</div>
						</div>
						<div class="layui-inline" style="padding-right: 0px;margin-right: 0px;">
							<button class="layui-btn icon-btn" lay-filter="formSubSearchBizVideo" lay-submit>
								<i class="layui-icon">&#xe615;</i>查询
							</button>
						</div>					
					</div>
				</div>
				<table class="layui-table" id="tableBizVideo" lay-filter="tableBizVideo"></table>
			</div>
		</div>
	</div>
</div>

<!-- 表格操作列 -->
<script type="text/html" id="tableBarBizVideo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- 表格状态列 -->
<script type="text/html" id="tableStateBizVideo">
#[[  {{#  if(d.status === '1'){ }}
    <span style="color: #23aa2e;">正常</span>
  {{#  } else { }}
	<span style="color: #ff0000;">禁止</span>
  {{#  } }}
]]#
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="modelBizVideo">
<div class="layui-card">
	<div class="layui-card-body" style="padding:0px;padding-top: 1px;">
	    <form id="modelBizVideoForm" lay-filter="modelBizVideoForm" class="layui-form model-form">
	        <input name="id" type="hidden"/>
			<table class="formTable">
				<tr>
					<td>标题</td>
					<td colspan="3" style="text-align: left;">
	                	<input name="title"  placeholder="请输入名称" type="text" class="layui-input" lay-verType="tips" lay-verify="required" required/>
	                </td>
				</tr>
				<tr>
					<td>封面</td>
					<td colspan="3" style="text-align: left;">
	                	<input name="cover"  placeholder="请输入名称" type="text" class="layui-input" lay-verType="tips" lay-verify="required" required/>
	                </td>
				</tr>
				<tr>
					<td>是否启用</td>
					<td colspan=3" style="text-align: left;">
						<select name="status" lay-filter="status" lay-verify="required" required>
							<option value="">--请选择--</option>
							<option value="0">禁用</option>
							<option value="1">启用</option>
						</select>
					</td>
				</tr>
				<tr>
					<td>内容</td>
					<td colspan="3" style="text-align: left;">
	                	<textarea name="content" id="content" cols="30" rows="10"></textarea>
	                </td>
				</tr>
				<tr>
					<td colspan="4">
			            <button class="layui-btn" lay-filter="modelSubmitBizVideoForm" lay-submit>保存</button>
	                </td>
				</tr>												
			</table> 
		</form>
	</div>
</div>
</script>

<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'util', 'tinymce'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
		var tinymce = layui.tinymce;
        
        form.render('select');
        
        // 渲染表格
        var insTb = table.render({
            elem: '#tableBizVideo',
            url: '#(ctx)/biz/video/listData', 
            page: true,
            toolbar: false,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers', title: '序号'},
				{field: 'coverImg', sort: false, title: '缩略图'},
                {field: 'name', sort: false, title: '名称'},
				{field: 'createUserName', sort: false, title: '来源于'},
                {
                    field: 'createTime', sort: false, templet: function (d) {
                        return util.toDateString(d.createTime);
                    }, title: '创建时间'
                },
				{field: 'status', sort: false, templet: '#tableStateBizVideo', title: '状态', align: 'center'},
                {align: 'left', toolbar: '#tableBarBizVideo', title: '操作', fixed: 'right',width: 170}
            ]],
        });

        // 添加
		$('#btnAddBizVideo').click(function () {
			showEditModel();
		});

        // 搜索
        form.on('submit(formSubSearchBizVideo)', function (data) {
            insTb.reload({where: data.field}, 'data');
        });

        // 工具条点击事件
        table.on('tool(tableBizVideo)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            if (layEvent === 'edit') { // 修改
            	showEditModel(data);
            } else if (layEvent === 'del') { 
                doDel(data.id, data.name);
            }
        });
        
        // 显示编辑弹窗
        function showEditModel(data) {
        	 admin.open({
                type: 1,
                title: (data ? '修改' : '添加') + '视频',
                content: $('#modelBizVideo').html(),
                area:'800px',
                shade: 0.3,
                offset: 't'	,
                success: function (layero, dIndex) {
                    $(layero).children('.layui-layer-content').css('overflow', 'visible');
                    var url = 'biz/video/save';
                    
                    var content = tinymce.render({
                       	elem: "#content",
                       	height: 600,
                       	width:'100%'
                    });
                    
                    form.val('modelBizVideoForm', data);  // 回显数据
                    // 表单提交事件
                    form.on('submit(modelSubmitBizVideoForm)', function (data) {
                        layer.load(2);
                        var formData={}; 
                        for(var key in data.field){
                        	formData['bizVideo.'+key]=data.field[key];
                        }
                        admin.req(url, formData, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.close(dIndex);
                                layer.msg(res.message, {icon: 1});
                                insTb.reload({}, 'data');
                            } else {
                                layer.msg(res.message, {icon: 2});
                            }
                        }, 'get');
                        return false;
                    });
                    form.render();
                }
            });
        }
        

        // 删除
        function doDel(id, name) {
        	layer.confirm('确定要克隆“【<span style="color:red;">' + name + '</span>】”吗？', {
                skin: 'layui-layer-admin',
                shade: .1
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('biz/video/delete', {
                    id: id
                }, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.message, {icon: 1});
                        insTb.reload({}, 'data');
                    } else {
                        layer.msg(res.message, {icon: 2});
                    }
                }, 'get');
            });
        }

    });
</script>
